import imaplib
import tkMessageBox
import Tkinter
import sys
from time import sleep



user = sys.argv[1]
password = sys.argv[2]

M = imaplib.IMAP4_SSL("imap.gmail.com")

M.login(user, password)
while 1:
	M.select()
	typ, data = M.search(None, 'UNSEEN')
	
	nums = data[0].split()
	if nums:
		for num in nums:
			typ, data = M.fetch(num, '(RFC822)')
			sender = data[0][1].split("smtp.mail=")[1].split()[0]
			subject = data[0][1].split("Subject: ")[1].split("\r\n")[0]
			if sender == "jaspersmit@flexusjeugdplein.nl" or sender == "forum@iculture.nl" or sender == "info@host1free.com" or sender == "scoutshop@scouting.nl" or sender == "daan.van.bennekom@me.com" or sender == "bcdev22@gmail.com": #TODO: replace this testline with proper sheet
				class App(object):
					def __init__(self, master):
						self.master = master

				root = Tkinter.Tk()
				root.withdraw()
				tkMessageBox.showwarning("Question", message="Receiver email from: '"+sender+"' with subject: '"+subject+"'", icon='warning', master=root)
				root.deiconify()

				app = App(root)
				root.withdraw()
	sleep(5)
	M.close()
M.logout()
